package legumes.client.ui.widgets.form;

import legumes.client.ui.widgets.form.item.AdressPrecisionFormItem;
import legumes.client.ui.widgets.form.item.BuildingFormItem;
import legumes.client.ui.widgets.form.item.CivilityEnumFormItem;
import legumes.client.ui.widgets.form.item.CountryFormItem;
import legumes.client.ui.widgets.form.item.FlatFormItem;
import legumes.client.ui.widgets.form.item.MoralPersonNameFormItem;
import legumes.client.ui.widgets.form.item.PhoneFormItem;
import legumes.client.ui.widgets.form.item.PhysicalPersonNameFormItem;
import legumes.client.ui.widgets.form.item.PlaceCalledFormItem;
import legumes.client.ui.widgets.form.item.StreetFormItem;
import legumes.client.ui.widgets.form.item.TownFormItem;
import legumes.client.ui.widgets.form.item.ZipCodeFormItem;
import legumes.shared.domain.CivilityEnum;
import legumes.shared.domain.PostalAdress;

import com.smartgwt.client.widgets.form.DynamicForm;

public class PostalAdressDynamicForm extends DynamicForm {

	private CivilityEnumFormItem civility;
	private PhysicalPersonNameFormItem lastName;
	private PhysicalPersonNameFormItem firstName;
	
	private MoralPersonNameFormItem companyName;
	private FlatFormItem flat;
	private BuildingFormItem building;
	private StreetFormItem street;
	private PlaceCalledFormItem placeCalled;
	private ZipCodeFormItem zipCode;
	private TownFormItem town;
	private CountryFormItem country;
	private PhoneFormItem phone1;
	private PhoneFormItem phone2;
	//Ex : Digicode; Give to concierge
	private AdressPrecisionFormItem adressPrecision;
	
	private PostalAdress postalAdressToEdit;
	
	public PostalAdressDynamicForm() {
		this(null);
	}

	public PostalAdressDynamicForm(PostalAdress postalAdressToEdit_) {
		super();
		postalAdressToEdit = postalAdressToEdit_;
		civility = new CivilityEnumFormItem();
		lastName = new PhysicalPersonNameFormItem("Nom", "Dupont");
		firstName = new PhysicalPersonNameFormItem("Prénom", "Jean-Pierre");
		
		companyName = new MoralPersonNameFormItem();
		flat = new FlatFormItem();
		building = new BuildingFormItem();
		street = new StreetFormItem();
		placeCalled = new PlaceCalledFormItem();
		zipCode = new ZipCodeFormItem();
		town = new TownFormItem();
		country = new CountryFormItem();
		phone1 = new PhoneFormItem("Tél fixe", "0123456789 / +33123456789", false);
		phone2 = new PhoneFormItem("Tél portable", "0623456789 / +33623456789", false);
		adressPrecision = new AdressPrecisionFormItem();
		
		initFieldsForEdition();
		
		setItems(civility, lastName, firstName,
				companyName, 
				flat, building, street, placeCalled,
				zipCode, town, country, 
				phone1, phone2, adressPrecision);
	}
	
	private void initFieldsForEdition(){
		if(postalAdressToEdit != null){
			civility.setValue( postalAdressToEdit.getCivility());
			lastName.setValue(postalAdressToEdit.getLastName());
			firstName.setValue(postalAdressToEdit.getFirstName());
			
			companyName.setValue(postalAdressToEdit.getCompanyName());
			flat.setValue(postalAdressToEdit.getFlat());
			building.setValue(postalAdressToEdit.getBuilding());
			street.setValue(postalAdressToEdit.getStreet());
			placeCalled.setValue(postalAdressToEdit.getPlaceCalled());
			zipCode.setValue(postalAdressToEdit.getZipCode());
			town.setValue(postalAdressToEdit.getTown());
			country.setValue(postalAdressToEdit.getCountry());
			phone1.setValue(postalAdressToEdit.getPhone1());
			phone2.setValue(postalAdressToEdit.getPhone2());
			adressPrecision.setValue(postalAdressToEdit.getAdressPrecision());
		}
	}

	public CivilityEnum getCivilityEnum(){
		return civility.getCivilityEnum();
	}
	
	public String getLastName(){
		return lastName.getValueAsString();
	}
	
	public String getFirstName(){
		return firstName.getValueAsString();
	}
	
	public String getCompanyName(){
		return companyName.getValueAsString();
	}
	
	public String getFlat(){
		return flat.getValueAsString();
	}
	
	public String getBuilding(){
		return building.getValueAsString();
	}
	
	public String getStreet(){
		return street.getValueAsString();
	}
	
	public String getPlaceCalled(){
		return placeCalled.getValueAsString();
	}
	
	public String getZipCode(){
		return zipCode.getValueAsString();
	}
	
	public String getTown(){
		return town.getValueAsString();
	}
	
	public String getCountry(){
		return country.getValueAsString();
	}
	
	public String getPhoneFixe(){
		return phone1.getValueAsString();
	}
	
	public String getPhonePortable(){
		return phone2.getValueAsString();
	}
	
	public String getAdressPrecision(){
		return adressPrecision.getValueAsString();
	}
	
	
}
